from appium import webdriver
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy

options = AppiumOptions()
options.load_capabilities({
	"platformName": "android",
	"appium:automationName": "uiautomator2",
	"appium:deviceName": "127.0.0.1:7555",
	"appium:appPackage": "io.appium.android.apis",
	"appium:appActivity": ".ApiDemos",
	"appium:ensureWebviewsHavePages": True,
	"appium:nativeWebScreenshot": True,
	"appium:newCommandTimeout": 3600,
	"appium:connectHardwareKeyboard": True
})

driver = webdriver.Remote("http://127.0.0.1:4723", options=options)

el1 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="OS")
el1.click()
el2 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="Morse Code")
el2.click()
el3 = driver.find_element(by=AppiumBy.ID, value="io.appium.android.apis:id/text")
el3.send_keys("xianmo")
driver.execute_script('mobile: pressKey', {"keycode": 4})
driver.execute_script('mobile: pressKey', {"keycode": 4})

driver.quit()